<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
	
	var caseTempalteTbl;
	$(function(){
		caseTempalteTbl = new S.Table({
			el:'#caseTempalteTbl',
			pager:true,
			pageSize:20,
			scroll:true,
			dbclick:function(data){
				editCT(data);
			},
			menus:{
				'编辑':function(tr){
					var idx =$(tr).index();
					var data = caseTempalteTbl.data[idx];
					if(data == null){return;}					
					editCT(data);
				},
				'删除':function(tr){
					var idx =$(tr).index();
					var data = caseTempalteTbl.data[idx];
					if(data == null){return;}					
					deleteCT([data]);
				}
			}
		});
		
		$('#btn_case_tempalte_add').click(function(){
			
			var dlg =new S.Dialog({
				title:'增加用例模板',
				width:500,
				height:200,
				modal:true,
				url:'${webcontext }/${pathvar.admin}/br/testing/case/template/edit',
				buttons:{
					'保存':function(){
						if(!this.form.validate()){new S.Info({text:'表单填写不完整',type:'warn'}).show(); return;}
						S.request({
							url:'${webcontext }/${pathvar.admin}/br/testing/case/template/save',
							data:this.form.param(),
							success:function(){
								new S.Info({text:'操作成功',type:'success'}).show();
								caseTempalteTbl.reload();
								dlg.remove();
							}
						});
						
					},
					'取消 ':function(){
						this.remove();
					}
				}
			});
			dlg.show();
		})
		
		function editCT(data){
			var dlg =new S.Dialog({
				title:'编辑用例模板',
				width:500,
				height:200,
				modal:true,
				url:'${webcontext }/${pathvar.admin}/br/testing/case/template/edit?id='+data.id,
				buttons:{
					'保存':function(){
						if(!this.form.validate()){new S.Info({text:'表单填写不完整',type:'warn'}).show(); return;}
						S.request({
							url:'${webcontext }/${pathvar.admin}/br/testing/case/template/update',
							data:this.form.param(),
							success:function(){
								new S.Info({text:'操作成功',type:'success'}).show();
								caseTempalteTbl.reload();
								dlg.remove();
							}
						});
					},
					'取消 ':function(){
						this.remove();
					}
				}
			});
			dlg.show();
		}
		
		
		$('#btn_case_tempalte_edit').click(function(){
			var items = caseTempalteTbl.getCheckedRow();
			if(items.length != 1){new S.Info({text:'请选择模板',type:'warn'}).show();return;}
			
			editCT(items[0])
		})
		
		function deleteCT(items){
			S.confirm('警告','确认要删除选中的模板?',function(){
				
				var ids = [];
				S.each(items,function(i,item){
					ids.push(item.id);
				});
				
				S.request({
					url:'${webcontext }/${pathvar.admin}/br/testing/case/template/delete',
					data:{ids:ids.join(',')},
					success:function(){
						new S.Info({text:'操作成功',type:'success'}).show();
						caseTempalteTbl.reload();
					}
				});
			},'danger');
		}
		$('#btn_case_tempalte_delete').click(function(){
			
			var items = caseTempalteTbl.getCheckedRow();
			if(items.length == 0){new S.Info({text:'请选择模板',type:'warn'}).show();return;}
			
			deleteCT(items);
		})
	});
</script>
<div class="toolbar">
	<span class="btn" id="btn_case_tempalte_add"><i class="icons newspaper_add"></i>增加</span>
	<span class="btn" id="btn_case_tempalte_edit"><i class="icons pencil"></i>修改</span>
	<span class="btn" id="btn_case_tempalte_delete"><i class="icons newspaper_delete"></i>删除</span>
</div>
<div class="content">
	<table height="400" id="caseTempalteTbl" ds="${webcontext }/${pathvar.admin}/br/testing/case/template/list">
		<tr>
			<td width="30" seq></td>
			<td width="80" checkall></td>
			<td>名称</td>
		</tr>
		<tr>
			<td>@{seq}</td>
			<td><input type="checkbox" name="id" value="@{id}"></td>
			<td>@{name}</td>
		</tr>
	</table>
</div>